﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using PlottingBasics.LINQHelpers;

namespace t_PlottingBasics
{
    [TestClass]
    public class t_ThinOut
    {
        [TestMethod]
        public void TestBasic()
        {
            double[] seq = new double[] {0.0, 1.0, 1.0, 1.0, 1.01, 1.01, 2.0};

            var result = seq.Thin((lastOne, thisOne) => Math.Abs(lastOne - thisOne) < 0.1).ToArray();
            Assert.AreEqual(4, result.Count(), "Wrong number of elements");
            Assert.AreEqual(0.0, result[0], "0 is wrong");
            Assert.AreEqual(1.0, result[1], "1 is wrong");
            Assert.AreEqual(1.01, result[2], "2 is wrong");
            Assert.AreEqual(2.0, result[3], "3 is wrong");
                
        }

        [TestMethod]
        public void TestIncrementalChanges()
        {
            double[] seq = new double[] { 0.0, 1.0, 1.05, 1.1, 1.15, 2.0 };
            var result = seq.Thin((lastOne, thisOne) => Math.Abs(lastOne - thisOne) < 0.1).ToArray();
            Assert.AreEqual(6, result.Count(), "Size is wrong");
            Assert.AreEqual(0.0, result[0], "0 is wrong");
            Assert.AreEqual(1.0, result[1], "1 is wrong");
            Assert.AreEqual(1.05, result[2], "2 is wrong");
            Assert.AreEqual(1.1, result[3], "3 is wrong");
            Assert.AreEqual(1.15, result[4], "4 is wrong");
            Assert.AreEqual(2.0, result[5], "5 is wrong");
        }

        [TestMethod]
        public void TestEndWithSequence()
        {
            double[] seq = new double[] { 0.0, 1.0, 1.05, 1.06, 1.07, 1.08 };
            var result = seq.Thin((lastOne, thisOne) => Math.Abs(lastOne - thisOne) <= 0.1).ToArray();
            Assert.AreEqual(3, result.Count(), "Size is wrong");
            Assert.AreEqual(0.0, result[0], "0 is wrong");
            Assert.AreEqual(1.0, result[1], "1 is wrong");
            Assert.AreEqual(1.08, result[2], "2 is wrong");
        }

        [TestMethod]
        public void TestEndWithSequenceOfLenOne()
        {
            double[] seq = new double[] { 0.0, 1.0, 1.05 };
            var result = seq.Thin((lastOne, thisOne) => Math.Abs(lastOne - thisOne) <= 0.1).ToArray();
            Assert.AreEqual(3, result.Count(), "Size is wrong");
            Assert.AreEqual(0.0, result[0], "0 is wrong");
            Assert.AreEqual(1.0, result[1], "1 is wrong");
            Assert.AreEqual(1.05, result[2], "2 is wrong");
        }

        [TestMethod]
        public void TestStartsWithSequence()
        {
            double[] seq = new double[] { 0.0, 0.01, 0.02, 0.03, 0.04, 1.0, 2.0 };
            var result = seq.Thin((lastOne, thisOne) => Math.Abs(lastOne - thisOne) <= 0.1).ToArray();
            Assert.AreEqual(4, result.Length, "Expected size is wrong");
            Assert.AreEqual(0.0, result[0], "0 is wrong");
            Assert.AreEqual(0.04, result[1], "1 is wrong");
            Assert.AreEqual(1.0, result[2], "2 is wrong");
            Assert.AreEqual(2.0, result[3], "3 is wrong");
        }

        [TestMethod]
        public void TestNoThnning()
        {
            double[] seq = new double[] { 0.0, 1.0, 2.0, 3.0 };
            var result = seq.Thin((lastOne, thisOne) => Math.Abs(lastOne - thisOne) <= 0.1).ToArray();
            Assert.AreEqual(4, result.Length, "Expected size is wrong");
            Assert.AreEqual(0.0, result[0], "0 is wrong");
            Assert.AreEqual(1.0, result[1], "1 is wrong");
            Assert.AreEqual(2.0, result[2], "2 is wrong");
            Assert.AreEqual(3.0, result[3], "3 is wrong");
        }
    }
}